<template>
  <div class="layout">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="route.path"
          router
          class="menu"
        >
          <el-menu-item index="/dashboard">
            <el-icon><Monitor /></el-icon>
            <span>仪表盘</span>
          </el-menu-item>
          <el-menu-item index="/categories">
            <el-icon><Files /></el-icon>
            <span>商品分类</span>
          </el-menu-item>
          <el-menu-item index="/products">
            <el-icon><Goods /></el-icon>
            <span>商品管理</span>
          </el-menu-item>
          <el-menu-item index="/orders">
            <el-icon><List /></el-icon>
            <span>订单管理</span>
          </el-menu-item>
          <el-menu-item index="/banners">
            <el-icon><Picture /></el-icon>
            <span>轮播图管理</span>
          </el-menu-item>
          <el-menu-item index="/settings">
            <el-icon><Setting /></el-icon>
            <span>系统设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header height="60px">
          <div class="header">
            <h2>商城管理系统</h2>
            <div class="user-info">
              <el-dropdown>
                <span class="user-name">
                  管理员 <el-icon><ArrowDown /></el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'
import { Monitor, Files, Goods, List, Picture, Setting, ArrowDown } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'

const route = useRoute()
const router = useRouter()

const handleLogout = async () => {
  try {
    await ElMessageBox.confirm('确定要退出登录吗？', '提示', {
      type: 'warning',
      confirmButtonText: '确定',
      cancelButtonText: '取消'
    })
    
    localStorage.removeItem('token')
    router.push('/login')
  } catch {
    // 用户取消操作
  }
}
</script>

<style scoped>
.layout {
  height: 100%;
}

.menu {
  height: 100%;
  border-right: none;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  border-bottom: 1px solid #eee;
  padding: 0 20px;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-name {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-name .el-icon {
  margin-left: 4px;
}

:deep(.el-aside) {
  border-right: 1px solid #eee;
}

:deep(.el-header) {
  padding: 0;
  background-color: #fff;
}

:deep(.el-main) {
  padding: 0;
  background-color: #f5f7fa;
}
</style> 